from common.sys.shell import Shell
from common.utils.toolkit import Log
import base64

class MediaPush:
    @staticmethod
    def push(path, bitrate="900k", maxrate="1000k", servername="stream", streamname="live", appname="movie"):
        cmd = " ".join(["ffmpeg", "-re", "-i", path, "-c:a", "aac", "-q:a", "0.8", "-c:v", "libx264", "-b:v", bitrate, "-maxrate", maxrate, "-vf", "scale=-1:720", "-r", "film", "-g", "3", "-f", "flv", "rtmp://{}/{}/{}".format(servername, streamname, appname)])
        Log.i(cmd)
        Shell.exec(cmd, True)
        #Shell.exec(["ffmpeg", "-re", "-i", path, "-c:a", "aac", "-q:a", "0.8", "-c:v", "libx264", "-b:v", bitrate, "-maxrate", maxrate, "-vf", "scale=-1:720", "-r", "film", "-g", "3", "-f", "flv", "rtmp://{}/{}/{}".format(servername, streamname, appname)], True)
